﻿using System;
using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UIToolBarTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetToolBar()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            Assert.IsNotNull(titleBar);
        }

        [TestMethod]
        public void ShouldGetAllToolBars()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UIToolBar> toolBars = window.UIToolBars();
            Assert.AreEqual(1, toolBars.Count);
            Assert.AreEqual("toolBar1", toolBars[0].AutomationId);
        }

        [TestMethod]
        public void ShouldGetCanMove()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            Assert.IsFalse(titleBar.CanMove);
        }

        [TestMethod]
        public void ShouldGetCanResize()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            Assert.IsFalse(titleBar.CanResize);
        }

        [TestMethod]
        public void ShouldGetCanRotate()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            Assert.IsFalse(titleBar.CanRotate);
        }

        [TestMethod]
        public void ShouldGetDockablePosition()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            Assert.IsFalse(titleBar.DockPosition.HasValue);
        }

        [TestMethod]
        public void ShouldGetExpandCollapseState()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            Assert.IsFalse(titleBar.ExpandCollapseState.HasValue);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ShowThrowExceptionOnExpandForUnsupportedToolBarExpand()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            titleBar.Expand();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ShowThrowExceptionOnCollapseForUnsupportedToolBarCollapse()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            titleBar.Collapse();
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void ShowThrowExceptionOnDockForUndockableToolBar()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIToolBar titleBar = window.UIToolBar("@AutomationId='toolBar1'");
            titleBar.Dock(DockPosition.Top);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}